﻿using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Xml.Linq;

namespace VQWEB.huongnghiep.BL
{
    public static class ReadXML
    {
        private static string path_xml = HttpContext.Current.Server.MapPath("~/huongnghiep/url.xml");
        public static void Routing(RouteCollection routes)
        {

            XDocument xdoc = XDocument.Load(path_xml);
            var query = from p in xdoc.Element("url").Descendants()
                        select p;
            foreach (XElement element in query)
            {
                string name = element.Attribute("name").Value.Trim();
                string url = element.Attribute("url").Value.Trim();
                string src = element.Attribute("src").Value.Trim();
                if (url.IndexOf("/", System.StringComparison.Ordinal) == 0)
                {
                    url = url.Remove(0, 1);
                }
                routes.MapPageRoute(name, url, src);
            }
        }
    }
}